package com.sgb.goods.view.adapter.publish;

import android.view.View;

import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.entity.ArrEntity;
import com.sgb.goods.utils.base.adapter.BaseCommonAdapter;
import com.swgk.core.customview.ItemInputTextView;

import java.util.List;

public class ArrAdapter extends BaseCommonAdapter<ArrEntity> {

    private ClickArr clickArr;
    private boolean isReset = false;

    public ArrAdapter() {
        super(R.layout.goods_item_arr, BR.viewModel);
    }

    @Override
    protected void convert(BaseViewHolder baseHolder, ViewDataBinding dataBinding, ArrEntity entity) {
        ItemInputTextView arrTv = baseHolder.getView(R.id.item_tv_arr);
        if (entity.isfill != null && 1 == entity.isfill) {
            arrTv.setStarTvVisibleOrGone(View.VISIBLE);
        } else {
            arrTv.setStarTvVisibleOrGone(View.GONE);
        }
        arrTv.setLabelName(entity.name);
        arrTv.setLabelHint("请选择");

        if (baseHolder.getPosition() == getData().size() - 1) {
            arrTv.setDeliverLineVG(false);
        } else {
            arrTv.setDeliverLineVG(true);
        }
        arrTv.setContent(entity.content);
        if (isReset) {
            arrTv.setContent("");
        }
        arrTv.setOnWholeItemClickListener(view -> {
            isReset = false;
            clickArr.clickArr(entity.type, baseHolder.getPosition(), entity.name, entity.id);
        });
    }

    public interface ClickArr {
        void clickArr(List<ArrEntity.ChildType> childType, int index, String pName, String pId);
    }

    public void OnClickArr(ClickArr clickArr) {
        this.clickArr = clickArr;
    }


    public void updateStatus(int index, String Content) {
        getData().get(index).content = Content;
        notifyDataSetChanged();
    }

    public void isReset(boolean isReset) {
        this.isReset = isReset;
    }
}
